package com.konsung.util;

import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Rect;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbManager;
import android.os.Environment;
import android.view.KeyEvent;

import com.konsung.bean.MeasureDataBean;
import com.konsung.bean.PatientBean;
import com.konsung.bean.PhysicalExaminationBean;
import com.konsung.bean.RecordAllMeasureResult;
import com.konsung.healthfile.R;
import com.konsung.ui.defineview.LoadingDialog;
import com.konsung.util.constant.GlobalConstant;
import com.pantum.mobileprint.LoadJNI;
import com.pantum.mobileprint.PantumPrint;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * 打印工具类
 */
public class PrintUtil {
    private LoadJNI loadjni = new LoadJNI();
    private static final String HEALTH_REPORT_PATH = Environment
            .getExternalStorageDirectory().getAbsolutePath();
    private final int urtConfig;
    private final int measureConfig;
    private MeasureDataBean measureBean;
    private RecordAllMeasureResult result; //需打印项

    //病人信息
    private PatientBean patient;
    //是否打印心电图
    private boolean isPrintHeart = false;
    //定义2个位图对象，在fragment创建的时候加载
    Bitmap bitmapPort;
    Bitmap bitmapPort2;
    Bitmap bitmapPort3;
    Bitmap bitmapEcg;
    private int bitmapWidthwidth;
    private int measureResultX;
    private int yGap = 80;
    private int contentSize = 48;
    private int columnInterval = 450;
    private int rowInterval = 60;
    private static final String TITLE_COLOR = "#c5ffcc";

    private LoadingDialog loadingDialog;

    private static final int END_Y = 3288; //内容区底部横线Y坐标
    private static final int END_Y_2 = 3288 * 2; //内容区底部横线Y坐标
    private static final int ONE_VALUE = 300; //一个测量项打印占用高度
    private static final int TWO_VALUE = 380; //两个测量项打印占用高度
    private static final int THREE_VALUE = 460; //三个测量项打印占用高度
    private static final int FOUR_VALUE = 520; //四个测量项打印占用高度
    private static final int URT_11_HEIGHT = 1100; //尿常规11项打印占用高度
    private static final int URT_14_HEIGHT = 1340; //尿常规14项打印占用高度
    private static final int RESULT_ADVICE_HEIGHT = 330; //结论及建议打印占用高度
    private static final int MID_OF_RESULT = 730; //检查结果中点X坐标
    private static final int MID_OF_UNIT = 1132; //单位中点X坐标
    private static final int MID_OF_REFERENCE = 1606; //参考范围中点X坐标
    private static final int ALARM_X = 2020; //提示是否不在正常范围起点X坐标
    private int offsetX1 = 250;
    private int offsetX2 = 136;
    private int offsetX3 = 210;
    private int offsetX4 = 246;
    private int pageOneY = 520; //第一页内容区起始Y坐标
    private int pageTwoY = 520; //第二页内容区起始Y坐标
    private int pageThreeY = 520; //第三页内容起始Y坐标
    private Integer resultConfig = -1; //诊断结果
    //记录需要打印的测量项，true代表打印在第一页，false代表第二页
    private Map<Integer, Boolean> printList = new HashMap<>();
    private Map<Integer, Boolean> printList2 = new HashMap<>(); //true 打印在第二页 false 打印在第三页
    private boolean overOnePage = false; //是否超过一页
    private boolean overTwoPage = false; //是否超过两页
    private String reportTime; //报告打印时间
    private boolean isPrintingInto;
    private boolean isPrinting;
    private Context context;
    private int deviceConfig;
    private Paint paint;
    private Bitmap personPic;
    private int totalHeight; //所有测量项累计的总高度
    DialogInterface.OnKeyListener keyListener = new DialogInterface.OnKeyListener() {
        /**
         * 点击时间回调
         * @param dialog 弹窗
         * @param keyCode 点击码
         * @param event 点击事件
         * @return 是否处理该事件
         */
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (keyCode == 4) { //f1
                if (loadingDialog.isShowing()) {
                    return true;
                }
            }
            return false;
        }
    };

    /**
     * 构造器
     * @param context 上下文
     * @param measureDataBean 测量数据
     * @param patientBean 居民信息
     */
    public PrintUtil(Context context, MeasureDataBean measureDataBean, PatientBean patientBean) {
        this.measureBean = measureDataBean;
        this.patient = patientBean;
        this.context = context;
        paint = new Paint();
        paint.setAntiAlias(true);
        urtConfig = measureDataBean.getUrtConfig();
        measureConfig = measureDataBean.getMeasureValue();
        deviceConfig = measureDataBean.getParamValue();
        loadingDialog = new LoadingDialog(context, "");
        loadingDialog.setOnKeyListener(keyListener);
    }

    /**
     * 检测打印机是否连接上
     * @param code 状态码
     * @return 是否连接上
     */
    public boolean checkUSB(int code) {
        isPrintingInto = false;
        if (code == 0) {
            //连接打印机成功
            UiUtils.post(new Runnable() {
                @Override
                public void run() {
                    ToastUtils.showShortToast(UiUtils.getString(R.string.dispose_print_waiting));
                }
            });
            isPrintingInto = true;
            return true;
        } else if (code == 3) {
            //打印机不存在
            UiUtils.post(new Runnable() {
                @Override
                public void run() {
                    ToastUtils.showShortToast(UiUtils.getString(R.string.dispose_print_usb));
                }
            });
            return false;
        } else if (code == 6) {
            //未获取打印机的权限
            UiUtils.post(new Runnable() {
                @Override
                public void run() {
                    ToastUtils.showShortToast(UiUtils.getString(R.string.dispose_print_again));
                }
            });
            return false;
        }
        UiUtils.post(new Runnable() {
            @Override
            public void run() {
                ToastUtils.showShortToast(UiUtils.getString(R.string.dispose_print_port));
            }
        });
        return false;
    }

    /**
     * 打印线程完成的方法
     */
    public void printFinish() {
        isPrinting = false;
        UiUtils.post(new Runnable() {
            @Override
            public void run() {
                ToastUtils.showShortToast(UiUtils.getString(R.string.dispose_print_finish));
                //回收bitmap
                if (bitmapPort != null) {
                    bitmapPort.recycle();
                    bitmapPort = null;
                }
                if (bitmapEcg != null) {
                    bitmapEcg.recycle();
                    bitmapEcg = null;
                }
                if (bitmapPort2 != null) {
                    bitmapPort2.recycle();
                    bitmapPort2 = null;
                }
            }
        });
    }

    /**
     * 打印方法
     * @param path 图片路径
     */
    public void printNew(String path) {

        PantumPrint pantumPrint = new PantumPrint();
        pantumPrint.print(context, path);
    }

    /**
     * 停止打印
     */
    public void cancelSendDataToServer() {
        if (loadingDialog != null && loadingDialog.isShowing()) {
            loadingDialog.setContent(UiUtils.getString(R.string
                    .dispose_print_failed) + UiUtils.getString(
                    R.string.dispose_print_data));
        }
        loadjni.cancelSendDataToServer();
    }

    /**
     * 检测打印机状态
     * @param context 上下文
     * @return 打印机状态
     */
    public boolean checkPrintUSB(Context context) {
        UsbDevice usbDevice = null;
        //进入方法后先将打印机状态置为false
        isPrintingInto = false;
        UsbManager usbManager = (UsbManager) context.getSystemService(Context
                .USB_SERVICE);

        if (usbManager == null) {
            //未得到USB管理者
            return false;
        }
        HashMap<String, UsbDevice> deviceList = usbManager.getDeviceList();

        Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();

        if (deviceList.size() == 0) {
            //不存在USB设备
            return false;
        }

        while (deviceIterator.hasNext()) {
            UsbDevice device = deviceIterator.next();
            if (device.getVendorId() == 9003) {
                //找到了打印设备
                usbDevice = device;
            }
        }
        if (usbDevice == null) {
            //未找到打印机设备
            return false;
        }
        isPrintingInto = true;
        return true;
    }

    /**
     * 开始打印
     */
    public void startPrint() {

        //判断是否需要打印心电图
        if (isPrinting) { //判断用户是否点击了打印
            return;
        }
        isPrintHeart = result.isPrintEcgReport();
        if (loadingDialog == null) {
            loadingDialog = new LoadingDialog(context, "");
        }
        //获取检查打印机端口连接的返回码
        int checkUSBCode = printByPantum1();
        if (!checkUSB(checkUSBCode)) {
            return;
        }
        loadingDialog.show();
        loadingDialog.setContent(UiUtils.getString(R
                .string.dispose_print)
                + UiUtils.getString(R.string
                .physical_examination_report));
        UiUtils.postShortThread(
                new Runnable() {
                    @Override
                    public void run() {
                        isPrinting = true;
                        if (isPrintingInto) {
                            //录入位图
                            drawOnBitmap();

                            File file1 = new File(HEALTH_REPORT_PATH,
                                    GlobalConstant.HEALTH_REPORT_NAME);
                            if (file1.exists()) {
                                int checkUSBCode = printByPantum1();
                                if (!checkUSB(checkUSBCode)) {
                                    loadingDialog.dismiss();
                                    return;
                                }
                                printNew(file1.getAbsolutePath());
                                file1.delete();
                            }
                            File file2 = new File(HEALTH_REPORT_PATH,
                                    GlobalConstant.HEALTH_REPORT_TWO);

                            if (file2.exists()) {
                                int checkUSBCode = printByPantum1();
                                if (!checkUSB(checkUSBCode)) {
                                    loadingDialog.dismiss();
                                    return;
                                }
                                printNew(file2.getAbsolutePath());
                                file2.delete();
                            }
                        }
                        if (isPrintingInto) {
                            if (isPrintHeart) {
                                //录入一个位图
                                InputStream resourceAsStream2 = UiUtils
                                        .getContent().getClass()
                                        .getClassLoader()
                                        .getResourceAsStream("assets/ecg.bmp");
                                if (bitmapEcg == null) {
                                    bitmapEcg = BitmapFactory
                                            .decodeStream(resourceAsStream2)
                                            .copy(Bitmap.Config.RGB_565, true);
                                    drawEcgImage();
                                    UiUtils.post(new Runnable() {
                                        @Override
                                        public void run() {
                                            loadingDialog.setContent(UiUtils
                                                    .getString(R.string.dispose_print) +
                                                    UiUtils.getString(R.string.health_ecg));
                                        }
                                    });
                                }
                                File file3 = new File(HEALTH_REPORT_PATH,
                                        GlobalConstant.HEALTH_ECG_NAME);
                                if (file3.exists()) {
                                    int checkUSBCode = printByPantum1();
                                    if (!checkUSB(checkUSBCode)) {
                                        loadingDialog.dismiss();
                                        return;
                                    }
                                    printNew(file3.getAbsolutePath());
                                    file3.delete();
                                }
                            }
                        }

                        printFinish();
                        loadingDialog.dismiss();
                    }
                }

        );
    }

    /**
     * 判断打印机是否连接
     * @return 打印机状态码
     */
    private int printByPantum1() {
        PantumPrint pantumPrint = new PantumPrint();
        pantumPrint.initPrint(UiUtils.getContent());
        return pantumPrint.connectUsb(UiUtils.getContent());
    }

    /**
     * 绘制内容到位图里
     */
    public void drawOnBitmap() {
        pageOneY = 520;
        pageTwoY = 520;
        printList.clear();
        printList2.clear();
        //画图
        try {
            if (checkPage()) {
                if (null == bitmapPort) {
                    InputStream resourceAsStream1 = UiUtils.getContent().getClass()
                            .getClassLoader().getResourceAsStream("assets/report.bmp");
                    bitmapPort = BitmapFactory.decodeStream(resourceAsStream1)
                            .copy(Bitmap.Config.RGB_565, true);
                    drawReportOnBitmap(bitmapPort);

                    resourceAsStream1.close();
                }
                if (null == bitmapPort2) {
                    InputStream resourceAsStream2 = UiUtils.getContent().getClass()
                            .getClassLoader().getResourceAsStream("assets/report2.bmp");
                    bitmapPort2 = BitmapFactory.decodeStream(resourceAsStream2)
                            .copy(Bitmap.Config.RGB_565, true);
                    drawReportOnBitmap2(bitmapPort2);
                    resourceAsStream2.close();
                }
                if (isMoreThanTwoPage()) {
                    //超过两页，即三页打印的情况
                    overOnePage = true;
                    overTwoPage = true;
                    if (null == bitmapPort3) {
                        InputStream resourceAsStream3 = UiUtils.getContent().getClass()
                                .getClassLoader().getResourceAsStream("assets/report3.bmp");
                        bitmapPort3 = BitmapFactory.decodeStream(resourceAsStream3)
                                .copy(Bitmap.Config.RGB_565, true);
                        drawReportOnBitmap3(bitmapPort3);
                        resourceAsStream3.close();
                    }
                } else {
                    //2页打印情况
                    overOnePage = true;
                    overTwoPage = false;
                }
            } else {
                overOnePage = false;
                if (null == bitmapPort) {
                    InputStream resourceAsStream1 = UiUtils.getContent().getClass()
                            .getClassLoader().getResourceAsStream("assets/report.bmp");
                    bitmapPort = BitmapFactory.decodeStream(resourceAsStream1)
                            .copy(Bitmap.Config.RGB_565, true);
                    drawReportOnBitmap(bitmapPort);
                    resourceAsStream1.close();
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 判断打印内容是否超过一页
     * @return true代表超过一页
     */
    private boolean checkPage() {
        int height = 520;
        if ((deviceConfig & (0x01 << 0)) != 0) { //心电、血氧、血压
            if (result.isPrintEcg()) {
                if (height + ONE_VALUE < END_Y) {
                    printList.put(KParamType.ECG_HR, true);
                } else {
                    if (height + ONE_VALUE < END_Y_2) {
                        printList2.put(KParamType.ECG_HR, true);
                    } else {
                        printList2.put(KParamType.ECG_HR, false);
                    }
                    printList.put(KParamType.ECG_HR, false);
                }
                height = height + ONE_VALUE;
            }

            if (result.isPrintBloodOx()) {
                if (height + TWO_VALUE < END_Y) {
                    printList.put(KParamType.SPO2_TREND, true);
                } else {
                    if (height + TWO_VALUE < END_Y_2) {
                        printList2.put(KParamType.SPO2_TREND, true);
                    } else {
                        printList2.put(KParamType.SPO2_TREND, false);
                    }
                    printList.put(KParamType.SPO2_TREND, false);
                }
                height = height + TWO_VALUE;
            }

            if (result.isPrintBloodPress()) {
                if (height + TWO_VALUE < END_Y) {
                    printList.put(KParamType.NIBP_SYS, true);
                } else {
                    if (height + TWO_VALUE < END_Y_2) {
                        printList2.put(KParamType.NIBP_SYS, true);
                    } else {
                        printList2.put(KParamType.NIBP_SYS, false);
                    }
                    printList.put(KParamType.NIBP_SYS, false);
                }
                height = height + TWO_VALUE;
            }
        }

        if (((deviceConfig & (0x01 << 4)) != 0
                || (deviceConfig & (0x01 << 5)) != 0) && result.isPrintTemp()) { //振海体温 热映体温
            if (height + ONE_VALUE < END_Y) {
                printList.put(KParamType.IRTEMP_TREND, true);
            } else {
                if (height + ONE_VALUE < END_Y_2) {
                    printList2.put(KParamType.IRTEMP_TREND, true);
                } else {
                    printList2.put(KParamType.IRTEMP_TREND, false);
                }
                printList.put(KParamType.IRTEMP_TREND, false);
            }
            height += ONE_VALUE;
        }
        if (((deviceConfig & (0x01 << 1)) != 0
                || (deviceConfig & (0x01 << 9)) != 0
                || (deviceConfig & (0x01 << 10)) != 0) && result.isPrintUrint()) { //恩普尿机 优利特 艾康
            if ((urtConfig & (0x01 << 0)) != 0) { //11
                if (height + URT_11_HEIGHT < END_Y) {
                    printList.put(KParamType.URINERT_LEU, true);
                } else {
                    if (height + URT_11_HEIGHT < END_Y_2) {
                        printList2.put(KParamType.URINERT_LEU, true);
                    } else {
                        printList2.put(KParamType.URINERT_LEU, false);
                    }
                    printList.put(KParamType.URINERT_LEU, false);
                }
                height += URT_11_HEIGHT;
            } else { //14
                if (height + URT_14_HEIGHT < END_Y) {
                    printList.put(KParamType.URINERT_LEU, true);
                } else {
                    if (height + URT_14_HEIGHT < END_Y_2) {
                        printList2.put(KParamType.URINERT_LEU, true);
                    } else {
                        printList2.put(KParamType.URINERT_LEU, false);
                    }
                    printList.put(KParamType.URINERT_LEU, false);
                }
                height += URT_14_HEIGHT;
            }
        }
        if (((deviceConfig & (0x01 << 2)) != 0
                || (deviceConfig & (0x01 << 6)) != 0
                || (deviceConfig & (0x01 << 8)) != 0
                || (deviceConfig & (0x01 << 16)) != 0)
                && result.isPrintBloodGlu()) { //三诺，百捷（单），艾康，倍稳
            if (height + ONE_VALUE < END_Y) {
                printList.put(KParamType.BLOODGLU_BEFORE_MEAL, true);
            } else {
                if (height + ONE_VALUE < END_Y_2) {
                    printList2.put(KParamType.BLOODGLU_BEFORE_MEAL, true);
                } else {
                    printList2.put(KParamType.BLOODGLU_BEFORE_MEAL, false);
                }
                printList.put(KParamType.BLOODGLU_BEFORE_MEAL, false);
            }
            height += ONE_VALUE;
        }
        if (((deviceConfig & (0x01 << 7)) != 0) && (result.isPrintBloodGlu()
                || result.isPrintUric() || result.isPrintChol())) { //百捷三合一
            if (height + THREE_VALUE < END_Y) {
                printList.put(KParamType.BLOODGLU_BEFORE_MEAL, true);
                printList.put(KParamType.URICACID_TREND, true);
                printList.put(KParamType.CHOLESTEROL_TREND, true);
            } else {
                if (height + THREE_VALUE < END_Y_2) {
                    printList2.put(KParamType.BLOODGLU_BEFORE_MEAL, true);
                    printList2.put(KParamType.URICACID_TREND, true);
                    printList2.put(KParamType.CHOLESTEROL_TREND, true);
                } else {
                    printList2.put(KParamType.BLOODGLU_BEFORE_MEAL, false);
                    printList2.put(KParamType.URICACID_TREND, false);
                    printList2.put(KParamType.CHOLESTEROL_TREND, false);
                }
                printList.put(KParamType.BLOODGLU_BEFORE_MEAL, false);
                printList.put(KParamType.URICACID_TREND, false);
                printList.put(KParamType.CHOLESTEROL_TREND, false);
            }
            height += THREE_VALUE;
        }

        if (((deviceConfig & (0x01 << 11)) != 0) && result.isPrintWbc()) { //白细胞
            if (height + ONE_VALUE < END_Y) {
                printList.put(KParamType.BLOOD_WBC, true);
            } else {
                if (height + ONE_VALUE < END_Y_2) {
                    printList2.put(KParamType.BLOOD_WBC, true);
                } else {
                    printList2.put(KParamType.BLOOD_WBC, false);
                }
                printList.put(KParamType.BLOOD_WBC, false);
            }
            height += ONE_VALUE;
        }
        if (((deviceConfig & (0x01 << 12)) != 0 // hemocue HD血红蛋白，
                || (deviceConfig & (0x01 << 13)) != 0 //优利特血红蛋白，
                || (deviceConfig & (0x01 << 14)) != 0) && result.isPrintHgb()) { //mission HD血红蛋白，
            if (height + TWO_VALUE < END_Y) {
                printList.put(KParamType.BLOOD_HGB, true);
            } else {
                if (height + TWO_VALUE < END_Y_2) {
                    printList2.put(KParamType.BLOOD_HGB, true);
                } else {
                    printList2.put(KParamType.BLOOD_HGB, false);
                }
                printList.put(KParamType.BLOOD_HGB, false);
            }
            height += TWO_VALUE;
        }
        if (((deviceConfig & (0x01 << 17)) != 0) && result.isPrintGhb()) { //尤尼德糖化血红蛋白
            if (height + THREE_VALUE < END_Y) {
                printList.put(KParamType.GHB_HBA1C_NGSP, true);
            } else {
                if (height + THREE_VALUE < END_Y_2) {
                    printList2.put(KParamType.GHB_HBA1C_NGSP, true);
                } else {
                    printList2.put(KParamType.GHB_HBA1C_NGSP, false);
                }
                printList.put(KParamType.GHB_HBA1C_NGSP, false);
            }
            height += THREE_VALUE;
        }
        if (((deviceConfig & (0x01 << 15)) != 0) && result.isPrintBloodFat()) { //艾康血脂
            if (height + FOUR_VALUE < END_Y) {
                printList.put(KParamType.BLOOD_FAT_CHO, true);
            } else {
                if (height + FOUR_VALUE < END_Y_2) {
                    printList2.put(KParamType.BLOOD_FAT_CHO, true);
                } else {
                    printList2.put(KParamType.BLOOD_FAT_CHO, false);
                }
                printList.put(KParamType.BLOOD_FAT_CHO, false);
            }
            height += FOUR_VALUE;
        }
        if ((measureConfig == 3) && result.isPrintBmi()) { //身高+体重
            if (height + THREE_VALUE < END_Y) {
                printList.put(KParamType.BMI, true);
            } else {
                if (height + THREE_VALUE < END_Y_2) {
                    printList2.put(KParamType.BMI, true);
                } else {
                    printList2.put(KParamType.BMI, false);
                }
                printList.put(KParamType.BMI, false);
            }
            height += THREE_VALUE;
        } else if ((measureConfig == 1) && result.isPrintBmi()) {
            if (height + ONE_VALUE < END_Y) {
                printList.put(KParamType.HEIGHT, true);
            } else {
                if (height + ONE_VALUE < END_Y_2) {
                    printList2.put(KParamType.HEIGHT, true);
                } else {
                    printList2.put(KParamType.HEIGHT, false);
                }
                printList.put(KParamType.HEIGHT, false);
            }
            height += ONE_VALUE;
        } else if ((measureConfig == 2) && result.isPrintBmi()) {
            if (height + ONE_VALUE < END_Y) {
                printList.put(KParamType.WEIGHT, true);
            } else {
                if (height + ONE_VALUE < END_Y_2) {
                    printList2.put(KParamType.WEIGHT, true);
                } else {
                    printList2.put(KParamType.WEIGHT, false);
                }
                printList.put(KParamType.WEIGHT, false);
            }
            height += ONE_VALUE;
        }

        if (height + RESULT_ADVICE_HEIGHT < END_Y) {
            printList.put(resultConfig, true);
        } else {
            if (height + RESULT_ADVICE_HEIGHT < END_Y_2) {
                printList2.put(resultConfig, true);
            } else {
                printList2.put(resultConfig, false);
            }
            printList.put(resultConfig, false);
        }
        height += RESULT_ADVICE_HEIGHT;
        totalHeight = height;
        return height > END_Y;
    }

    /**
     * 该方法在超过一页的基础上继续判断页数是否大于2页
     * @return true超过两页 false 不超过两页
     */
    private boolean isMoreThanTwoPage() {
        return (totalHeight - END_Y) > END_Y;
    }


    /**
     * 画体检报告到一个bitmap中
     * @param bitmap 装载体检报告的bitmap容器
     */
    private void drawReportOnBitmap(Bitmap bitmap) {

        Canvas canvas = new Canvas(bitmap);

        int x; //x方向坐标
        int y; //y方向坐标
        //打印标题的起始位置
        final int titleX = 700;
        final int titleY = 120;
        //打印个人图标的起始位置
        final int persionPicX = 140;
        final int persionPicY = 270;
        //打印测量结果的起始位置
        measureResultX = 104;

        // 画布宽度
        bitmapWidthwidth = bitmap.getWidth();

        //设置画笔
        Paint paint = new Paint();

        //打印报告图标
        Bitmap hosPic = BitmapFactory.decodeResource(context.getResources(), R
                .mipmap.pic_hos);
        canvas.drawBitmap(hosPic, titleX, titleY - 120, null);

        //打印第一行标题
        paint.setColor(Color.BLACK);
        paint.setTextSize(75);
        x = titleX + 200;
        y = titleY;

//        canvas.drawText(UiUtils.getString(R.string.x_district_temp), x, y,
//                paint);
        //打印第二行标题
        x = 1000;
        y = titleY + 10;
        canvas.drawText(UiUtils.getString(R.string.x_report), x, y,
                paint);

        paint.setStrokeWidth((float) 5);
        canvas.drawLine(measureResultX, y + 60,
                bitmapWidthwidth - measureResultX, y + 60,
                paint);

        //照片终点位置
        int picEndX = 344;
        int picEndY = 522;
        //打印照片
        if (personPic != null) {
            canvas.drawBitmap(personPic, null, new Rect(persionPicX,
                    persionPicY - 25, picEndX, picEndY - 25), null);
        }

        //第一行个人信息
        //打印个人信息的起始位置
        paint.setTextSize(48);
        final int persionInfoX = 250;
        final int persionInfoY = 350;
        x = persionInfoX;
        y = persionInfoY;
        canvas.drawText(UiUtils.getContent().getString(R.string.name1), x, y,
                paint);
        x += 150;
        canvas.drawText(patient.getName(), x, y, paint);
        x += 550;
        canvas.drawText(UiUtils.getContent().getString(R.string.sex1), x, y,
                paint);
        x += 150;
        canvas.drawText(IdCardUtil.getSexFormDB(patient
                .getSex()), x, y, paint);

        x += 340;
        canvas.drawText(UiUtils.getContent().getString(R.string.measure_time_colon),
                x, y, paint);
        x += 260;
        String measureTime = UiUtils.getDateFormat(UiUtils.DateState.LONG)
                .format(new Date(measureBean.getMeasureTime()));
        canvas.drawText(measureTime, x, y, paint);

        //第二行个人信息
        x = persionInfoX;
        y = persionInfoY + 100;
        canvas.drawText(UiUtils.getContent().getString(R.string.age1),
                x, y, paint);
        x += 150;
        canvas.drawText(patient.getAge() + "", x, y, paint);
        x += 100;
        canvas.drawText(UiUtils.getString(R.string.year), x, y, paint);

        x += 450;
        canvas.drawText(UiUtils.getContent().getString(R.string.doctor),
                x, y, paint);
        x += 150;
        canvas.drawText("" + measureBean.getDoctor(), x, y, paint);
        //绘制测量数据
        printMeasureData(canvas, paint, 1);

        x = measureResultX;
        y = 3378;
        reportTime = UiUtils.getDateFormat(UiUtils.DateState.LONG).format(new Date());
        canvas.drawText(UiUtils.getContent().getString(R.string.print_report), x, y, paint);
        x += 270;
        canvas.drawText("" + reportTime, x, y, paint);

        x += 1680;
        canvas.drawText(UiUtils.getContent().getString(R.string.p_page1),
                x, y, paint);

        x = measureResultX;
        paint.setStrokeWidth((float) 1);
        canvas.drawLine(measureResultX, y - 60,
                bitmapWidthwidth - measureResultX, y - 60,
                paint);
        // ### 生成位图文件 ###
        saveBitmapFile(bitmap, GlobalConstant.HEALTH_REPORT_NAME, 50);
        bitmapPort.recycle();
        bitmapPort = null; //释放资源
    }

    /**
     * 打印测量项
     * @param canvas 画布
     * @param paint 画笔
     * @param page 打印在第几页的页数值
     */
    private void printMeasureData(Canvas canvas, Paint paint, int page) {
        if (printList.containsKey(KParamType.ECG_HR)) {
            //打印心率测量项
            int x = 0;
            int y = 0;
            if (result.isPrintEcg()) {
                if (printList.get(KParamType.ECG_HR) && page == 1) {
                    //打印在第一页，每次打印记录高度的Y坐标对应增加
                    y = pageOneY;
                    pageOneY += ONE_VALUE;
                    drawFistTitle(x, y, canvas, KParamType.ECG_HR);
                } else if (!printList.get(KParamType.ECG_HR)) {
                    //打印在第二页
                    if (printList2.get(KParamType.ECG_HR) && page == 2) {
                        y = pageTwoY;
                        pageTwoY += ONE_VALUE;
                    } else if (!printList2.get(KParamType.ECG_HR) && page == 3) {
                        y = pageThreeY;
                        pageThreeY += ONE_VALUE;
                    }
                    drawFistTitle(x, y, canvas, KParamType.ECG_HR);
                }
            }
        }
        if (printList.containsKey(KParamType.SPO2_TREND)) {
            //打印血氧测量项
            if (result.isPrintBloodOx()) {
                int x = measureResultX;
                int y = 0;
                if (printList.get(KParamType.SPO2_TREND) && page == 1) {
                    y = pageOneY;
                    pageOneY += TWO_VALUE;
                    //打印血氧测量结果
                    y = drawFistTitle(x, y, canvas, KParamType.SPO2_TREND);

                    //脉率测量结果
                    y = drawSecondTitle(x, y, canvas, KParamType.SPO2_PR);
                } else if (!printList.get(KParamType.SPO2_TREND)) {
                    if (printList2.get(KParamType.SPO2_TREND) && page == 2) {
                        y = pageTwoY;
                        pageTwoY += TWO_VALUE;
                    } else if (!printList2.get(KParamType.SPO2_TREND) && page == 3) {
                        y = pageThreeY;
                        pageThreeY += TWO_VALUE;
                    }
                    //打印血氧测量结果
                    y = drawFistTitle(x, y, canvas, KParamType.SPO2_TREND);

                    //脉率测量结果
                    y = drawSecondTitle(x, y, canvas, KParamType.SPO2_PR);
                }
            }
        }
        if (printList.containsKey(KParamType.NIBP_SYS)) {
            //打印血压测量结果
            if (result.isPrintBloodPress()) {
                int x = measureResultX;
                int y = 0;
                if (printList.get(KParamType.NIBP_SYS) && page == 1) {
                    y = pageOneY;
                    pageOneY += TWO_VALUE;
                    //打印血压测量结果
                    y = drawFistTitle(x, y, canvas, KParamType.NIBP_SYS);

                    //舒张压测量结果
                    y = drawSecondTitle(x, y, canvas, KParamType.NIBP_DIA);
                } else if (!printList.get(KParamType.NIBP_SYS)) {
                    if (printList2.get(KParamType.NIBP_SYS) && page == 2) {
                        y = pageTwoY;
                        pageTwoY += TWO_VALUE;
                    } else if (!printList2.get(KParamType.NIBP_SYS) && page == 3) {
                        y = pageThreeY;
                        pageThreeY += TWO_VALUE;
                    }
                    //打印血压测量结果
                    y = drawFistTitle(x, y, canvas, KParamType.NIBP_SYS);

                    //舒张压测量结果
                    y = drawSecondTitle(x, y, canvas, KParamType.NIBP_DIA);
                }
            }
        }
        if (printList.containsKey(KParamType.IRTEMP_TREND)) {
            //打印体温测量结果
            if (result.isPrintTemp()) {
                int x = 0;
                int y = 0;
                if (printList.get(KParamType.IRTEMP_TREND) && page == 1) {
                    y = pageOneY;
                    pageOneY += ONE_VALUE;
                    y = drawFistTitle(x, y, canvas, KParamType.IRTEMP_TREND);
                } else if (!printList.get(KParamType.IRTEMP_TREND)) {
                    if (printList2.get(KParamType.IRTEMP_TREND) && page == 2) {
                        y = pageTwoY;
                        pageTwoY += ONE_VALUE;
                    } else if (!printList2.get(KParamType.IRTEMP_TREND) && page == 3) {
                        y = pageThreeY;
                        pageThreeY += ONE_VALUE;
                    }

                    y = drawFistTitle(x, y, canvas, KParamType.IRTEMP_TREND);
                }
            }
        }
        if (printList.containsKey(KParamType.URINERT_LEU)) {
            if (result.isPrintUrint()) {
                int x = 0;
                int y = 0;
                if (printList.get(KParamType.URINERT_LEU) && page == 1) {
                    y = pageOneY;
                    pageOneY += URT_11_HEIGHT;
                    y = drawFistTitle(x, y, canvas, KParamType.URINERT_LEU);
                    y = drawSecondTitle(x, y, canvas, KParamType.URINERT_NIT);
                    y = drawSecondTitle(x, y, canvas, KParamType.URINERT_UBG);
                    y = drawSecondTitle(x, y, canvas, KParamType.URINERT_PRO);
                    y = drawSecondTitle(x, y, canvas, KParamType.URINERT_PH);
                    y = drawSecondTitle(x, y, canvas, KParamType.URINERT_SG);
                    y = drawSecondTitle(x, y, canvas, KParamType.URINERT_BLD);
                    y = drawSecondTitle(x, y, canvas, KParamType.URINERT_KET);
                    y = drawSecondTitle(x, y, canvas, KParamType.URINERT_BIL);
                    y = drawSecondTitle(x, y, canvas, KParamType.URINERT_GLU);
                    y = drawSecondTitle(x, y, canvas, KParamType.URINERT_ASC);
                    //当初测量保存的是14测量项配置
                    if (((urtConfig & (0x01 << 2)) != 0)) {
                        pageOneY -= URT_11_HEIGHT;
                        pageOneY += URT_14_HEIGHT;
                        y = drawSecondTitle(x, y, canvas, KParamType.URINERT_ALB);
                        y = drawSecondTitle(x, y, canvas, KParamType.URINERT_CRE);
                        y = drawSecondTitle(x, y, canvas, KParamType.URINERT_CA);
                    } else if (((urtConfig & (0x01 << 1)) != 0)) {
                        //当初测量保存的是11 + 2测量项配置
                        pageOneY -= URT_11_HEIGHT;
                        pageOneY += URT_14_HEIGHT;
                        y = drawSecondTitle(x, y, canvas, KParamType.URINERT_ALB);
                        y = drawSecondTitle(x, y, canvas, KParamType.URINERT_CRE);
                        y = drawSecondTitle(x, y, canvas, KParamType.URINERT_AC);
                    }
                } else if (!printList.get(KParamType.URINERT_LEU)) {
                    if (printList2.get(KParamType.URINERT_LEU) && page == 2) {
                        y = pageTwoY;
                        pageTwoY += URT_11_HEIGHT;
                    } else if (!printList2.get(KParamType.URINERT_LEU) && page == 3) {
                        y = pageThreeY;
                        pageThreeY += URT_11_HEIGHT;
                    }
                    y = drawFistTitle(x, y, canvas, KParamType.URINERT_LEU);
                    y = drawSecondTitle(x, y, canvas, KParamType.URINERT_NIT);
                    y = drawSecondTitle(x, y, canvas, KParamType.URINERT_UBG);
                    y = drawSecondTitle(x, y, canvas, KParamType.URINERT_PRO);
                    y = drawSecondTitle(x, y, canvas, KParamType.URINERT_PH);
                    y = drawSecondTitle(x, y, canvas, KParamType.URINERT_SG);
                    y = drawSecondTitle(x, y, canvas, KParamType.URINERT_BLD);
                    y = drawSecondTitle(x, y, canvas, KParamType.URINERT_KET);
                    y = drawSecondTitle(x, y, canvas, KParamType.URINERT_BIL);
                    y = drawSecondTitle(x, y, canvas, KParamType.URINERT_GLU);
                    y = drawSecondTitle(x, y, canvas, KParamType.URINERT_ASC);
                    //当初测量保存的是14测量项配置
                    if (((urtConfig & (0x01 << 2)) != 0)) {
                        pageTwoY -= URT_11_HEIGHT;
                        pageTwoY += URT_14_HEIGHT;
                        y = drawSecondTitle(x, y, canvas, KParamType.URINERT_ALB);
                        y = drawSecondTitle(x, y, canvas, KParamType.URINERT_CRE);
                        y = drawSecondTitle(x, y, canvas, KParamType.URINERT_CA);
                    } else if (((urtConfig & (0x01 << 1)) != 0)) {
                        //当初测量保存的是11 + 2测量项配置
                        pageTwoY -= URT_11_HEIGHT;
                        pageTwoY += URT_14_HEIGHT;
                        y = drawSecondTitle(x, y, canvas, KParamType.URINERT_ALB);
                        y = drawSecondTitle(x, y, canvas, KParamType.URINERT_CRE);
                        y = drawSecondTitle(x, y, canvas, KParamType.URINERT_AC);
                    }
                }
            }
        }

        if (printList.containsKey(KParamType.BLOODGLU_BEFORE_MEAL)) {
            if (result.isPrintBloodGlu()) {
                int x = 0;
                int y = 0;
                if (printList.get(KParamType.BLOODGLU_BEFORE_MEAL) && page == 1) {
                    y = pageOneY;
                    pageOneY += ONE_VALUE;
                    //默认显示空腹
                    if (measureBean.getTrendValue(KParamType.BLOODGLU_AFTER_MEAL)
                            != GlobalConstant.INVALID_DATA) {
//                        pageOneY -= ONE_VALUE;
//                        pageOneY += THREE_VALUE;
                        y = drawFistTitle(x, y, canvas, KParamType.BLOODGLU_AFTER_MEAL);
                    } else {
                        y = drawFistTitle(x, y, canvas, KParamType.BLOODGLU_BEFORE_MEAL);
                    }
                } else if (!printList.get(KParamType.BLOODGLU_BEFORE_MEAL)) {
                    if (printList2.get(KParamType.BLOODGLU_BEFORE_MEAL) && page == 2) {
                        y = pageTwoY;
                        pageTwoY += ONE_VALUE;
                    } else if (!printList2.get(KParamType.BLOODGLU_BEFORE_MEAL) && page == 3) {
                        y = pageThreeY;
                        pageThreeY += ONE_VALUE;
                    }
                    //默认显示空腹
                    if (measureBean.getTrendValue(KParamType.BLOODGLU_AFTER_MEAL)
                            != GlobalConstant.INVALID_DATA) {
                        y = drawFistTitle(x, y, canvas, KParamType.BLOODGLU_AFTER_MEAL);
                    } else {
                        y = drawFistTitle(x, y, canvas, KParamType.BLOODGLU_BEFORE_MEAL);
                    }
                }
            }
        }
        if (printList.containsKey(KParamType.BLOOD_WBC)) {
            //打印白细胞结果
            if (result.isPrintWbc()) {
                int x = 0;
                int y = 0;
                if (printList.get(KParamType.BLOOD_WBC) && page == 1) {
                    y = pageOneY;
                    pageOneY += ONE_VALUE;
                    y = drawFistTitle(x, y, canvas, KParamType.BLOOD_WBC);
                } else if (!printList.get(KParamType.BLOOD_WBC)) {
                    if (printList2.get(KParamType.BLOOD_WBC) && page == 2) {
                        y = pageTwoY;
                        pageTwoY += ONE_VALUE;
                    } else if (!printList2.get(KParamType.BLOOD_WBC) && page == 3) {
                        y = pageThreeY;
                        pageThreeY += ONE_VALUE;
                    }
                    y = drawFistTitle(x, y, canvas, KParamType.BLOOD_WBC);
                }
            }
        }

        if (printList.containsKey(KParamType.BLOOD_HGB)) {
            //打印血红蛋白
            if (result.isPrintHgb()) {
                int x = 0;
                int y = 0;
                if (printList.get(KParamType.BLOOD_HGB) && page == 1) {
                    y = pageOneY;
                    pageOneY += TWO_VALUE;
                    y = drawFistTitle(x, y, canvas, KParamType.BLOOD_HGB);
                    //打印红细胞压积值测量结果
                    y = drawSecondTitle(x, y, canvas, KParamType.BLOOD_HCT);
                } else if (!printList.get(KParamType.BLOOD_HGB)) {
                    if (printList2.get(KParamType.BLOOD_HGB) && page == 2) {
                        y = pageTwoY;
                        pageTwoY += TWO_VALUE;
                    } else if (!printList2.get(KParamType.BLOOD_HGB) && page == 3) {
                        y = pageThreeY;
                        pageThreeY += TWO_VALUE;
                    }
                    y = drawFistTitle(x, y, canvas, KParamType.BLOOD_HGB);
                    //打印红细胞压积值测量结果
                    y = drawSecondTitle(x, y, canvas, KParamType.BLOOD_HCT);
                }
            }
        }
        if (printList.containsKey(KParamType.URICACID_TREND)) {
            //尿酸 CHOLESTEROL_TREND
            if (result.isPrintUric()) {
                int x = 0;
                int y = 0;
                if (printList.get(KParamType.URICACID_TREND) && page == 1) {
                    y = pageOneY;
                    pageOneY += ONE_VALUE;
                    y = drawFistTitle(x, y, canvas, KParamType.URICACID_TREND);
                } else if (!printList.get(KParamType.URICACID_TREND)) {
                    if (printList2.get(KParamType.URICACID_TREND) && page == 2) {
                        y = pageTwoY;
                        pageTwoY += ONE_VALUE;
                    } else if (!printList2.get(KParamType.URICACID_TREND) && page == 3) {
                        y = pageThreeY;
                        pageThreeY += ONE_VALUE;
                    }
                    y = drawFistTitle(x, y, canvas, KParamType.URICACID_TREND);
                }
            }
        }

        if (printList.containsKey(KParamType.CHOLESTEROL_TREND)) {
            //总胆固醇
            if (result.isPrintChol()) {
                int x = 0;
                int y = 0;
                if (printList.get(KParamType.CHOLESTEROL_TREND) && page == 1) {
                    y = pageOneY;
                    pageOneY += ONE_VALUE;
                    y = drawFistTitle(x, y, canvas, KParamType.CHOLESTEROL_TREND);
                } else if (!printList.get(KParamType.CHOLESTEROL_TREND)) {
                    if (printList2.get(KParamType.CHOLESTEROL_TREND) && page == 2) {
                        y = pageTwoY;
                        pageTwoY += ONE_VALUE;
                    } else if (!printList2.get(KParamType.CHOLESTEROL_TREND) && page == 3) {
                        y = pageThreeY;
                        pageThreeY += ONE_VALUE;
                    }
                    y = drawFistTitle(x, y, canvas, KParamType.CHOLESTEROL_TREND);
                }
            }
        }

        if (printList.containsKey(KParamType.GHB_HBA1C_NGSP)) {
            if (result.isPrintGhb()) {
                int x = measureResultX;
                int y = 0;
                if (printList.get(KParamType.GHB_HBA1C_NGSP) && page == 1) {
                    y = pageOneY;
                    pageOneY += THREE_VALUE;
                    y = drawFistTitle(x, y, canvas, KParamType.GHB_HBA1C_NGSP);

                    y = drawSecondTitle(x, y, canvas, KParamType.GHB_HBA1C_IFCC);

                    y = drawSecondTitle(x, y, canvas, KParamType.GHB_EAG);
                } else if (!printList.get(KParamType.GHB_HBA1C_NGSP)) {
                    if (printList2.get(KParamType.GHB_HBA1C_NGSP) && page == 2) {
                        y = pageTwoY;
                        pageTwoY += THREE_VALUE;
                    } else if (!printList2.get(KParamType.GHB_HBA1C_NGSP) && page == 3) {
                        y = pageThreeY;
                        pageThreeY += THREE_VALUE;
                    }
                    y = drawFistTitle(x, y, canvas, KParamType.GHB_HBA1C_NGSP);

                    y = drawSecondTitle(x, y, canvas, KParamType.GHB_HBA1C_IFCC);

                    y = drawSecondTitle(x, y, canvas, KParamType.GHB_EAG);
                }
            }
        }
        if (printList.containsKey(KParamType.BLOOD_FAT_CHO)) {
            //打印血脂四项测量结果
            if (result.isPrintBloodFat()) {
                int x = 0;
                int y = 0;
                if (printList.get(KParamType.BLOOD_FAT_CHO) && page == 1) {
                    y = pageOneY;
                    pageOneY += FOUR_VALUE;
                    y = drawFistTitle(x, y, canvas, KParamType.BLOOD_FAT_CHO);

                    y = drawSecondTitle(x, y, canvas, KParamType.BLOOD_FAT_TRIG);
                    y = drawSecondTitle(x, y, canvas, KParamType.BLOOD_FAT_HDL);
                    y = drawSecondTitle(x, y, canvas, KParamType.BLOOD_FAT_LDL);
                } else if (!printList.get(KParamType.BLOOD_FAT_CHO)) {
                    if (printList2.get(KParamType.BLOOD_FAT_CHO) && page == 2) {
                        y = pageTwoY;
                        pageTwoY += FOUR_VALUE;
                    } else if (!printList2.get(KParamType.BLOOD_FAT_CHO) && page == 3) {
                        y = pageThreeY;
                        pageThreeY += FOUR_VALUE;
                    }
                    y = drawFistTitle(x, y, canvas, KParamType.BLOOD_FAT_CHO);

                    y = drawSecondTitle(x, y, canvas, KParamType.BLOOD_FAT_TRIG);
                    y = drawSecondTitle(x, y, canvas, KParamType.BLOOD_FAT_HDL);
                    y = drawSecondTitle(x, y, canvas, KParamType.BLOOD_FAT_LDL);
                }
            }
        }
        if (printList.containsKey(KParamType.BMI)) {
            if (result.isPrintBmi()) {
                int x = measureResultX;
                int y = 0;
                if (printList.get(KParamType.BMI) && page == 1) {
                    y = pageOneY;
                    pageOneY += THREE_VALUE;
                    y = drawFistTitle(x, y, canvas, KParamType.BMI);
                    y = drawSecondTitle(x, y, canvas, KParamType.HEIGHT);
                    y = drawSecondTitle(x, y, canvas, KParamType.WEIGHT);
                } else if (!printList.get(KParamType.BMI)) {
                    if (printList2.get(KParamType.BMI) && page == 2) {
                        y = pageTwoY;
                        pageTwoY += THREE_VALUE;
                    } else if (!printList2.get(KParamType.BMI) && page == 3) {
                        y = pageThreeY;
                        pageThreeY += THREE_VALUE;
                    }
                    y = drawFistTitle(x, y, canvas, KParamType.BMI);
                    y = drawSecondTitle(x, y, canvas, KParamType.HEIGHT);
                    y = drawSecondTitle(x, y, canvas, KParamType.WEIGHT);
                }
            }
        } else if (printList.containsKey(KParamType.HEIGHT)) {
            if (result.isPrintBmi()) {
                int x = measureResultX;
                int y = 0;
                if (printList.get(KParamType.HEIGHT) && page == 1) {
                    y = pageOneY;
                    pageOneY += ONE_VALUE;
                    y = drawFistTitle(x, y, canvas, KParamType.HEIGHT);
                } else if (!printList.get(KParamType.HEIGHT)) {
                    if (printList2.get(KParamType.HEIGHT) && page == 2) {
                        y = pageTwoY;
                        pageTwoY += ONE_VALUE;
                    } else if (!printList2.get(KParamType.HEIGHT) && page == 3) {
                        y = pageThreeY;
                        pageThreeY += ONE_VALUE;
                    }
                    y = drawFistTitle(x, y, canvas, KParamType.HEIGHT);
                }
            }
        } else if (printList.containsKey(KParamType.WEIGHT)) {
            if (result.isPrintBmi()) {
                int x = measureResultX;
                int y = 0;
                if (printList.get(KParamType.WEIGHT) && page == 1) {
                    y = pageOneY;
                    pageOneY += ONE_VALUE;
                    y = drawFistTitle(x, y, canvas, KParamType.WEIGHT);
                } else if (!printList.get(KParamType.WEIGHT)) {
                    if (printList2.get(KParamType.WEIGHT) && page == 2) {
                        y = pageTwoY;
                        pageTwoY += ONE_VALUE;
                    } else if (!printList2.get(KParamType.WEIGHT) && page == 3) {
                        y = pageThreeY;
                        pageThreeY += ONE_VALUE;
                    }
                    y = drawFistTitle(x, y, canvas, KParamType.WEIGHT);
                }
            }
        }
        if (printList.containsKey(resultConfig)) {
            //打印结论与建议
            int x = 0;
            int y = 0;
            if (printList.get(resultConfig) && page == 1) {
                y = pageOneY;
                pageOneY += RESULT_ADVICE_HEIGHT;
                printResultAdvice(canvas, paint, x, y);
            } else if (!printList.get(resultConfig)) {
                if (printList2.get(resultConfig) && page == 2) {
                    y = pageTwoY;
                    pageTwoY += RESULT_ADVICE_HEIGHT;
                } else if (!printList2.get(resultConfig) && page == 3) {
                    y = pageThreeY;
                    pageThreeY += RESULT_ADVICE_HEIGHT;
                }
                printResultAdvice(canvas, paint, x, y);
            }
        }
    }

    /**
     * 为了居中显示，计算需要打印的字符串起点X坐标
     * @param mid 中线
     * @param text 字符串
     * @param paint 画笔
     * @return text起点x坐标
     */
    private int getXStart(int mid, String text, Paint paint) {
        float textLength = paint.measureText(text);
        return (int) (mid - textLength / 2);
    }

    /**
     * 绘制第一栏标题和内容
     * @param x x轴距离
     * @param y y轴距离
     * @param canvas 画布
     * @param param 对应的参数值
     * @return 移动后的y轴距离
     */
    private int drawFistTitle(int x, int y, Canvas canvas, int param) {
        x = measureResultX + 80;
        PhysicalExaminationBean examinationBean = MeasureUtil.getPhysicalExaminationBean(param,
                measureBean);
        y = drawReportTitle(examinationBean.getTitleName(), x, y, canvas, paint, true);
        y += 80;
        paint.setTextSize(contentSize);
        canvas.drawText(examinationBean.getMeasureName(), x, y, paint);
        x = getXStart(MID_OF_RESULT, examinationBean.getMeasureValue(), paint);
        canvas.drawText(examinationBean.getMeasureValue(), x, y, paint);
        x = getXStart(MID_OF_UNIT, examinationBean.getUnit(), paint);
        canvas.drawText(examinationBean.getUnit(), x, y, paint);
        x = getXStart(MID_OF_REFERENCE, examinationBean.getScope(), paint);
        canvas.drawText(examinationBean.getScope(), x, y, paint);
        canvas.drawText(examinationBean.getHint(), ALARM_X, y, paint);

        return y;
    }

    /**
     * 绘制第二栏标题和内容
     * @param x x轴距离
     * @param y y轴距离
     * @param canvas 画布
     * @param param 对应的参数值
     * @return 移动后的y轴距离
     */
    private int drawSecondTitle(int x, int y, Canvas canvas, int param) {

        PhysicalExaminationBean examinationBean = MeasureUtil.getPhysicalExaminationBean(param,
                measureBean);
        x = measureResultX + 80;
        y += yGap;
        paint.setTextSize(contentSize);
        canvas.drawText(examinationBean.getMeasureName(), x, y, paint);
        x = getXStart(MID_OF_RESULT, examinationBean.getMeasureValue(), paint);
        canvas.drawText(examinationBean.getMeasureValue(), x, y, paint);
        x += offsetX2;
        canvas.drawText(examinationBean.getHint(), ALARM_X, y, paint);
        x += offsetX3;

        //康尚尿机不需要绘制单位
        Boolean urtFlag = param == KParamType.URINERT_ALB
                || param == KParamType.URINERT_CA
                || param == KParamType.URINERT_CRE;
        if ((deviceConfig & (0x01 << 1)) != 0 && urtFlag) {
            x = getXStart(MID_OF_UNIT, "/", paint);
            canvas.drawText("/", x, y, paint);
        } else {
            x = getXStart(MID_OF_UNIT, examinationBean.getUnit(), paint);
            canvas.drawText(examinationBean.getUnit(), x, y, paint);
        }
        x = getXStart(MID_OF_REFERENCE, examinationBean.getScope(), paint);
        canvas.drawText(examinationBean.getScope(), x, y, paint);
        return y;
    }

    /**
     * 打印结论与建议
     * @param canvas 画布
     * @param paint 画笔
     * @param x 打印起点X坐标
     * @param y 打印起点Y坐标
     */
    private void printResultAdvice(Canvas canvas, Paint paint, int x, int y) {
        x = measureResultX + 80;
        y += 20;
        drawReportTitle(UiUtils.getContent().getString(R.string.p_advice), x, y, canvas, paint,
                false);
        x = measureResultX;
        y += 100;
        paint.setStyle(Paint.Style.STROKE);
        int adviceEndY = y + 250;
        canvas.drawRect(x, y, bitmapWidthwidth - measureResultX, adviceEndY, paint);
        x += 20;
        y += 50;
        paint.setTextSize(48);
        paint.setStyle(Paint.Style.FILL);
//        if (!TextUtils.isEmpty(measureBean.getEcgDiagnoseResult())) {
//            if (advice.length() > 45) {
//                String substring = advice.substring(0, 45);
//                canvas.drawText("" + substring, x, y, paint);
//            }
//            if (advice.length() > 90) {
//                y += rowInterval;
//                String substring = advice.substring(45, 90);
//                canvas.drawText("" + substring, x, y, paint);
//            }
//            if (advice.length() > 135) {
//                y += rowInterval;
//                String substring = advice.substring(90, 135);
//                canvas.drawText("" + substring, x, y, paint);
//            }
//            if (advice.length() > 180) {
//                y += rowInterval;
//                String substring1 = advice.substring(135, 180);
//                canvas.drawText("" + substring1, x, y, paint);
//
//                y += rowInterval;
//                String substring2 = advice.substring(180);
//                canvas.drawText("" + substring2, x, y, paint);
//            }
//        }
    }

    /**
     * 画体检报告到一个bitmap中
     * @param bitmap 装载体检报告的bitmap容器
     */
    private void drawReportOnBitmap2(Bitmap bitmap) {

        Canvas canvas = new Canvas(bitmap);

        int x; //x方向坐标
        int y; //y方向坐标
        //打印标题的起始位置
        final int titleX = 700;
        final int titleY = 120;
        //打印个人图标的起始位置
        final int persionPicX = 140;
        final int persionPicY = 270;
        //打印测量结果的起始位置
        measureResultX = 104;

        // 画布宽度
        bitmapWidthwidth = bitmap.getWidth();

        //设置画笔
        Paint paint = new Paint();

        //打印报告图标
        Bitmap hosPic = BitmapFactory.decodeResource(context.getResources(), R
                .mipmap.pic_hos);
        canvas.drawBitmap(hosPic, titleX, titleY - 120, null);

        //打印第一行标题
        paint.setColor(Color.BLACK);
        paint.setTextSize(75);

//        canvas.drawText(UiUtils.getString(R.string.x_district_temp), x, y,
//                paint);
        //打印第二行标题
        x = 1000;
        y = titleY + 10;
        canvas.drawText(UiUtils.getString(R.string.x_report), x, y,
                paint);

        paint.setStrokeWidth((float) 5);
        canvas.drawLine(measureResultX, y + 60,
                bitmapWidthwidth - measureResultX, y + 60,
                paint);

        //照片终点位置
        int picEndX = 344;
        int picEndY = 522;
        //打印照片 TODO
        if (personPic != null) {
            canvas.drawBitmap(personPic, null, new Rect(persionPicX,
                    persionPicY - 25, picEndX, picEndY - 25), null);
        }

        //第一行个人信息
        //打印个人信息的起始位置
        paint.setTextSize(48);
        final int persionInfoX = 250;
        final int persionInfoY = 350;
        x = persionInfoX;
        y = persionInfoY;
        canvas.drawText(UiUtils.getContent().getString(R.string.name1), x, y,
                paint);
        x += 150;
        canvas.drawText(patient.getName(), x, y, paint);
        x += 550;
        canvas.drawText(UiUtils.getContent().getString(R.string.sex1), x, y,
                paint);
        x += 150;
        canvas.drawText(IdCardUtil.getSexFormDB(patient
                .getSex()), x, y, paint);

        x += 330;
        canvas.drawText(UiUtils.getContent().getString(R.string.physical_examination_time1),
                x, y, paint);
        x += 280;
        String measureTime = UiUtils.getDateFormat(UiUtils.DateState.LONG)
                .format(new Date(measureBean.getMeasureTime()));
        canvas.drawText(measureTime, x, y, paint);

        //第二行个人信息
        x = persionInfoX;
        y = persionInfoY + 100;
        canvas.drawText(UiUtils.getContent().getString(R.string.age1),
                x, y, paint);
        x += 150;
        canvas.drawText(patient.getAge() + "", x, y, paint);
        x += 100;
        canvas.drawText(UiUtils.getString(R.string.year), x, y, paint);

        x += 450;
        canvas.drawText(UiUtils.getContent().getString(R.string.doctor),
                x, y, paint);
        x += 150;
        canvas.drawText("" + measureBean.getDoctor(), x, y, paint);

        printMeasureData(canvas, paint, 2);

        x = measureResultX;
        y = 3378;
        canvas.drawText(UiUtils.getString(R.string.print_report), x, y, paint);
        x += 270;
        canvas.drawText("" + reportTime, x, y, paint);

        x += 1680;
        canvas.drawText(UiUtils.getContent().getString(R.string.p_page2),
                x, y, paint);

        x = measureResultX;
        paint.setStrokeWidth((float) 1);
        canvas.drawLine(measureResultX, y - 60,
                bitmapWidthwidth - measureResultX, y - 60,
                paint);
        // ### 生成位图文件 ###
        saveBitmapFile(bitmap, GlobalConstant.HEALTH_REPORT_TWO, 50);
        bitmapPort2.recycle();
        bitmapPort2 = null; //释放资源
    }

    /**
     * 画体检报告到一个bitmap中
     * @param bitmap 装载体检报告的bitmap容器
     */
    private void drawReportOnBitmap3(Bitmap bitmap) {

        Canvas canvas = new Canvas(bitmap);

        int x; //x方向坐标
        int y; //y方向坐标
        //打印标题的起始位置
        final int titleX = 700;
        final int titleY = 120;
        //打印个人图标的起始位置
        final int persionPicX = 140;
        final int persionPicY = 270;
        //打印测量结果的起始位置
        measureResultX = 104;

        // 画布宽度
        bitmapWidthwidth = bitmap.getWidth();

        //设置画笔
        Paint paint = new Paint();

        //打印报告图标
        Bitmap hosPic = BitmapFactory.decodeResource(context.getResources(), R
                .mipmap.pic_hos);
        canvas.drawBitmap(hosPic, titleX, titleY - 120, null);

        //打印第一行标题
        paint.setColor(Color.BLACK);
        paint.setTextSize(75);

//        canvas.drawText(UiUtils.getString(R.string.x_district_temp), x, y,
//                paint);
        //打印第二行标题
        x = 1000;
        y = titleY + 10;
        canvas.drawText(UiUtils.getString(R.string.x_report), x, y,
                paint);

        paint.setStrokeWidth((float) 5);
        canvas.drawLine(measureResultX, y + 60,
                bitmapWidthwidth - measureResultX, y + 60,
                paint);

        //照片终点位置
        int picEndX = 344;
        int picEndY = 522;
        //打印照片 TODO
        if (personPic != null) {
            canvas.drawBitmap(personPic, null, new Rect(persionPicX,
                    persionPicY - 25, picEndX, picEndY - 25), null);
        }

        //第一行个人信息
        //打印个人信息的起始位置
        paint.setTextSize(48);
        final int persionInfoX = 250;
        final int persionInfoY = 350;
        x = persionInfoX;
        y = persionInfoY;
        canvas.drawText(UiUtils.getContent().getString(R.string.name1), x, y,
                paint);
        x += 150;
        canvas.drawText(patient.getName(), x, y, paint);
        x += 550;
        canvas.drawText(UiUtils.getContent().getString(R.string.sex1), x, y,
                paint);
        x += 150;
        canvas.drawText(IdCardUtil.getSexFormDB(patient
                .getSex()), x, y, paint);

        x += 330;
        canvas.drawText(UiUtils.getContent().getString(R.string.physical_examination_time1),
                x, y, paint);
        x += 280;
        String measureTime = UiUtils.getDateFormat(UiUtils.DateState.LONG)
                .format(new Date(measureBean.getMeasureTime()));
        canvas.drawText(measureTime, x, y, paint);

        //第二行个人信息
        x = persionInfoX;
        y = persionInfoY + 100;
        canvas.drawText(UiUtils.getContent().getString(R.string.age1),
                x, y, paint);
        x += 150;
        canvas.drawText(patient.getAge() + "", x, y, paint);
        x += 100;
        canvas.drawText(UiUtils.getString(R.string.year), x, y, paint);

        x += 450;
        canvas.drawText(UiUtils.getContent().getString(R.string.doctor),
                x, y, paint);
        x += 150;
        canvas.drawText("" + measureBean.getDoctor(), x, y, paint);

        printMeasureData(canvas, paint, 3);

        x = measureResultX;
        y = 3378;
        canvas.drawText(UiUtils.getString(R.string.print_report), x, y, paint);
        x += 270;
        canvas.drawText("" + reportTime, x, y, paint);

        x += 1680;
        canvas.drawText(UiUtils.getContent().getString(R.string.p_page3),
                x, y, paint);

        x = measureResultX;
        paint.setStrokeWidth((float) 1);
        canvas.drawLine(measureResultX, y - 60,
                bitmapWidthwidth - measureResultX, y - 60,
                paint);
        // ### 生成位图文件 ###
        saveBitmapFile(bitmap, GlobalConstant.HEALTH_REPORT_THREE, 50);
        bitmapPort3.recycle();
        bitmapPort3 = null; //释放资源
    }

    /**
     * 画心电图
     */
    private void drawEcgImage() {
        Canvas canvas = new Canvas(bitmapEcg);
        //设置画笔
        Paint paint = new Paint();
        measureResultX = 104;
        int x; //x方向坐标
        int y; //y方向坐标

        paint.setStyle(Paint.Style.STROKE);
        x = measureResultX;
        y = measureResultX;
        //画打印的矩形边框
        canvas.drawRect(x, y, 1653, 600, paint);
        canvas.drawRect(1653, y, 3202, 600, paint);
        canvas.drawRect(x, 600, 3202, 2264, paint);

        String pr = measureBean.getPr() == GlobalConstant.INVALID_DATA ? UiUtils.getString(R.string
                .invalid_data) : String.valueOf(measureBean.getPr());
        String qrs = measureBean.getQrs() == GlobalConstant.INVALID_DATA ? UiUtils.getString(R
                .string.invalid_data) : String.valueOf(measureBean.getQrs());
        String qt = measureBean.getQt() == GlobalConstant.INVALID_DATA ? UiUtils.getString(R.string
                .invalid_data) : String.valueOf(measureBean.getQt());
        String qtc = measureBean.getQtc() == GlobalConstant.INVALID_DATA ? UiUtils.getString(R
                .string.invalid_data) : String.valueOf(measureBean.getQtc());
        String pAxis = measureBean.getPAxis() == GlobalConstant.INVALID_DATA ? UiUtils.getString(R
                .string.invalid_data) : String.valueOf(measureBean.getPAxis());
        String qrsAxis = measureBean.getQrsAxis() == GlobalConstant.INVALID_DATA ? UiUtils
                .getString(R.string.invalid_data) : String.valueOf(measureBean.getQrsAxis());
        String tAxis = measureBean.getTAxis() == GlobalConstant.INVALID_DATA ? UiUtils.getString(R
                .string.invalid_data) : String.valueOf(measureBean.getTAxis());
        String rv5 = measureBean.getRv5() == GlobalConstant.INVALID_DATA ?
                UiUtils.getString(R.string.invalid_data) : measureBean.getRv5() / GlobalConstant
                .FACTOR + "";
        String sv1 = measureBean.getSv1() == GlobalConstant.INVALID_DATA ?
                UiUtils.getString(R.string.invalid_data) : measureBean.getSv1() / GlobalConstant
                .FACTOR + "";
        String rv5PlusSv1 = measureBean.getRv5() + measureBean.getSv1() < 0 ?
                UiUtils.getString(R.string.invalid_data)
                : (measureBean.getRv5() + measureBean.getSv1()) / GlobalConstant.FACTOR + "";
        String ecgHr = UiUtils.getString(R.string.HR)
                + UiUtils.getString(R.string.width_colon)
                + String.valueOf(measureBean.getTrendValue(KParamType.ECG_HR)
                / GlobalConstant.INT_FACTOR) + UiUtils.getString(R.string.blank)
                + UiUtils.getString(R.string.health_unit_bpm); //心率测量值
        String ecgPr = UiUtils.getString(R.string.pr) + UiUtils.getString(R.string
                .width_colon) + pr + UiUtils.getString(R.string.blank) + UiUtils.getString(R
                .string.unit_ms); //PR间隔
        String ecgQrs = UiUtils.getString(R.string.qrs) + UiUtils.getString(R.string.width_colon)
                + qrs + UiUtils.getString(R.string.blank) + UiUtils.getString(R.string.unit_ms);
        //p/QRS间隔
        String ecgQtQtc = UiUtils.getString(R.string.qtQtc) + UiUtils.getString(R.string
                .width_colon) + qt + "/" + qtc + UiUtils.getString(R.string.blank) + UiUtils
                .getString(R.string.unit_ms); //QT/QTC间隔
        String ecgPQrsT = UiUtils.getString(R.string.P_QRS_T) + UiUtils.getString(R.string
                .width_colon) + pAxis + "/" + qrsAxis + "/" + tAxis + UiUtils.getString(R.string
                .blank) + UiUtils.getString(R.string.unit_limit); //P/QRS/T轴
        String ecgRvSv = UiUtils.getString(R.string.rv5Sv1) + UiUtils.getString(R.string
                .width_colon) + rv5 + "/" + sv1 + UiUtils.getString(R.string.blank) + UiUtils
                .getString(R.string.unit_mv); //RV5/SV1
        String ecgRvAddSv = UiUtils.getString(R.string.rv5Sv1Add) + UiUtils.getString(R.string
                .width_colon) + rv5PlusSv1 + UiUtils.getString(R.string.blank) + UiUtils
                .getString(R.string.unit_mv); //RV5+SV1
        String ecgResult = measureBean.getEcgDiagnoseResult().equals("0.00") ? "" : measureBean
                .getEcgDiagnoseResult(); //心电诊断结果
        paint.setColor(Color.BLACK);
        paint.setStyle(Paint.Style.FILL);
        paint.setTextSize(48);
        //顶部病人基本信息
        String patientInfo = patient.getName() + "   " + IdCardUtil.getSexFormDB(patient
                .getSex()) + "   " + patient.getAge() + UiUtils.getString(R.string.year) + "  " +
                " " + patient.getIdcard() + "   " + UiUtils.getString(R.string.measure_time_colon)
                + UiUtils.getDateFormat(UiUtils.DateState.LONG)
                .format(new Date(measureBean.getMeasureTime()));
        canvas.drawText(patientInfo, 130, 90, paint);
        x += 20;
        y += 60;
        canvas.drawText(ecgHr, x, y, paint);
        y += 65;
        canvas.drawText(ecgPr, x, y, paint);
        y += 65;
        canvas.drawText(ecgQrs, x, y, paint);
        y += 65;
        canvas.drawText(ecgQtQtc, x, y, paint);
        y += 65;
        canvas.drawText(ecgPQrsT, x, y, paint);
        y += 65;
        canvas.drawText(ecgRvSv, x, y, paint);
        y += 65;
        canvas.drawText(ecgRvAddSv, x, y, paint);
        x = 880;
        y = measureResultX + 60;
        canvas.drawText(UiUtils.getString(R.string.ecg_diagnose_result), x, y, paint);
        //心电诊断结果每行显示15个字，超过则换行
        if (ecgResult.length() > 0) {
            if (ecgResult.length() > 15) {
                y += 65;
                String substring = ecgResult.substring(0, 15);
                canvas.drawText(substring, x, y, paint);
            }
            if (ecgResult.length() > 30) {
                y += 65;
                String substring = ecgResult.substring(15, 30);
                canvas.drawText(substring, x, y, paint);
            }
            if (ecgResult.length() > 45) {
                y += 65;
                String substring = ecgResult.substring(30, 45);
                canvas.drawText(substring, x, y, paint);
            }
            if (ecgResult.length() > 60) {
                y += 65;
                String substring = ecgResult.substring(45, 60);
                canvas.drawText(substring, x, y, paint);
            }
            if (ecgResult.length() > 75) {
                y += 65;
                String substring = ecgResult.substring(60, 75);
                canvas.drawText(substring, x, y, paint);
            }
            int end = ecgResult.length() % 15;
            String substring;
            if (end == 0) {
                substring = ecgResult.substring(ecgResult.length() - 15, ecgResult.length());
            } else {
                substring = ecgResult.substring(ecgResult.length() - end, ecgResult.length());
            }
            y += 65;
            canvas.drawText(substring, x, y, paint);
        }

        x = 1673;
        y = measureResultX + 60;
        canvas.drawText(UiUtils.getString(R.string.expert_diagnose_result), x, y, paint);

        //心电图宽3098px，高1664px
        HeartImage.drawEcgImage(measureBean, canvas, 3098, 1664);

        paint.setStyle(Paint.Style.STROKE);
        paint.setColor(Color.parseColor("#70AD47"));
        paint.setStrokeWidth((float) 1);

        Matrix matrix = new Matrix();
        matrix.postRotate(-90);
        Bitmap bmp = Bitmap.createBitmap(bitmapEcg, 0, 0, bitmapEcg.getWidth(), bitmapEcg
                .getHeight(), matrix, true);
        Canvas newCanvas = new Canvas(bmp);
        //打印标题的起始位置
        final int titleX = 700;
        final int titleY = 120;
        //打印报告图标
        Bitmap hosPic = BitmapFactory.decodeResource(context.getResources(), R.mipmap.pic_hos);
        newCanvas.drawBitmap(hosPic, titleX, titleY - 120, null);
        hosPic.recycle();
        hosPic = null;

        //打印第一行标题
        paint.setColor(Color.BLACK);
        paint.setStyle(Paint.Style.FILL);
        paint.setTextSize(75);

        //打印第二行标题
        x = 1000;
        y = titleY + 10;
        newCanvas.drawText(UiUtils.getString(R.string.x_report), x, y, paint);

        paint.setStrokeWidth((float) 5);
        newCanvas.drawLine(measureResultX, y + 60, bmp.getWidth() - measureResultX, y + 60,
                paint);

        paint.setTextSize(48);
        x = measureResultX;
        y = 3378;
        newCanvas.drawText(UiUtils.getContent().getString(R.string.print_report), x, y, paint);
        x += 270;
        newCanvas.drawText(reportTime, x, y, paint);

        x += 1680;
        paint.setStrokeWidth((float) 1);
        newCanvas.drawLine(measureResultX, y - 60, bmp.getWidth() - measureResultX, y - 60,
                paint);
        if (overOnePage) {
            newCanvas.drawText(UiUtils.getContent().getString(R.string.p_page3), x, y, paint);
        } else {
            newCanvas.drawText(UiUtils.getContent().getString(R.string.p_page2), x, y, paint);
        }

        saveBitmapFile(bmp, GlobalConstant.HEALTH_ECG_NAME, 90);
        bitmapEcg = null; //释放资源
    }

    /**
     * 生成体检报告的位图文件
     * @param bitmapPort 资源位图
     * @param fileName 文件名字
     * @param sampleSize 压缩比例（1-100）
     */
    private void saveBitmapFile(Bitmap bitmapPort, String fileName, int sampleSize) {
        File file = new File(HEALTH_REPORT_PATH, fileName);
        try {
            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
            bitmapPort.compress(Bitmap.CompressFormat.JPEG, sampleSize, bos);
            bos.flush();
            bos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 画打印报告中的标题栏
     * @param title 标题名
     * @param x 标题起始x
     * @param y 标题起始y
     * @param canvas 画布
     * @param paint 画笔
     * @param b 是否包含了副标题栏
     * @return Y轴
     */
    private int drawReportTitle(String title, int
            x, int y, Canvas canvas, Paint paint, boolean b) {
        x = measureResultX;
        paint.setStrokeWidth((float) 2);
        canvas.drawLine(x, y,
                bitmapWidthwidth - measureResultX, y,
                paint);
        y += 10;
        paint.setColor(Color.parseColor(TITLE_COLOR));
        canvas.drawRect(x, y,
                bitmapWidthwidth - measureResultX, y + 80,
                paint);

        x += 80;
        y += 60;
        paint.setTextSize(58);
        paint.setColor(Color.BLACK);
        canvas.drawText(title, x, y, paint);

        paint.setColor(Color.BLACK);

        if (b) {
            // subtitle 副标题栏
            paint.setTextSize(48);
            y += 80;
            canvas.drawText(UiUtils.getString(R.string.item_name), x, y, paint);

            x += columnInterval;
            canvas.drawText(UiUtils.getString(R.string.check_result), x, y, paint);

            x += columnInterval;
            canvas.drawText(UiUtils.getString(R.string.unit), x, y, paint);

            x += columnInterval;
            canvas.drawText(UiUtils.getString(R.string.reference_value), x, y, paint);

            x += columnInterval;
            canvas.drawText(UiUtils.getString(R.string.hint), x, y, paint);

            paint.setStrokeWidth((float) 1);
            y += 20;
            canvas.drawLine(measureResultX, y,
                    bitmapWidthwidth - measureResultX, y,
                    paint);
        }
        return y;
    }

    /**
     * 当前是否打印
     * @return 是否打印
     */
    public boolean getPrinting() {
        return isPrintingInto;
    }

    /**
     * 设置测量数据
     * @param bean 测量数据
     */
    public void setMeasureBean(MeasureDataBean bean) {
        this.measureBean = bean;
    }

    /**
     * 设置打印项
     * @param result 需打印项
     */
    public void setRecordAllPrintResult(RecordAllMeasureResult result) {
        this.result = result;
    }

}